package com.guigu.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.Menus;
import com.guigu.pojo.Roles;
import com.guigu.pojo.SystemUsers;
import com.guigu.pojo.Users;
import com.guigu.service.MenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class MenusController {

    //自动注入
    @Autowired
    MenusService menusService;

    //显示权限数据
    @RequestMapping("show.action")
    public List<Menus> show(Users users){

        System.out.println("用户数据"+users);


            return menusService.show(users);

    }

    //显示后台权限菜单数据
    @RequestMapping("SystemUsers.action")
    public List<Menus> systemShow(SystemUsers systemUsers){

        System.out.println("--------------"+systemUsers);

        return menusService.systemShow(systemUsers);
    }

    //查找各个绝色的菜单
    @RequestMapping("querySystembyrid.action")
    public List querySystembyrid(Roles roles){

        return menusService.querySystembyrid(roles);
    }


    //面包屑导航
    @RequestMapping("quertop.action")
    public List<Menus> quertop(Integer mid,SystemUsers systemUsers){

        System.out.println("菜单id"+mid);
        System.out.println("用户"+systemUsers);

        return menusService.quertop(mid,systemUsers);
    }

    //前端用户选中的面包屑导航
    @RequestMapping("useractive.action")
    public List<Menus> useractive(Integer mid,Users users){

        System.out.println("菜单id"+mid);
        System.out.println("用户"+users);

        return menusService.querusertop(mid,users);
    }

    //显示所有菜单
    @RequestMapping("showmenusall.action")
    public List<Menus> showmenusall(){

        return menusService.showmenusall();
    }

    //分页显示所有菜单
    @RequestMapping("querallmenus.action")
    public Page<Menus> querallmenus(Integer grade,
                                    Menus menus,
                                    @RequestParam(value = "pageno",defaultValue = "1") Integer pageno,
                                    @RequestParam(value = "pagesize",defaultValue = "5") Integer pagesize){
        return menusService.querallmenus(grade,menus,pageno,pagesize);
    }

    //添加菜单
    @RequestMapping("addmenus.action")
    public Map addmenus(Menus menus,Integer menusgrade){
        menus.setState(0);

        return menusService.addmenus(menus,menusgrade);
    };

    //查找所有的一级菜单
    @GetMapping("querallfirstmenus.action")
    public List<Menus> querallfirstmenus(){
        return menusService.querallfirstmenus();
    }

    //查找所有的二级菜单
    @GetMapping("querallsecondmenus.action")
    public List<Menus> querallsecondmenus(){
        return menusService.querallsecondmenus();
    }

    //菜单状态修改
    @RequestMapping("altermenusbyid.action")
    public Map altermenusbyid(Menus menus){
        return menusService.altermenusbyid(menus);
    }

    //批量修改
    @RequestMapping("alterallmenus.action")
    public Map alterallmenus(Menus menus,Integer[] mid){


        return menusService.alterallmenus(menus,mid);
    }
}
